/*     */ package com.zimbra.cs.datasource.imap;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.mailbox.Folder;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import java.util.Collections;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ final class SyncState
/*     */ {
/*     */   private final Mailbox mbox;
/*     */   private final Folder inboxFolder;
/*     */   private final Map<Integer, FolderSyncState> folders;
/*     */   private boolean hasRemoteInboxChanges;
/*     */   private int lastChangeId;
/*     */   private MessageChanges inboxChanges;
/*     */   
/*     */   SyncState(Mailbox mbox)
/*     */     throws ServiceException
/*     */   {
/*  42 */     this.mbox = mbox;
/*  43 */     this.inboxFolder = mbox.getFolderById(null, 2);
/*  44 */     this.folders = Collections.synchronizedMap(new HashMap());
/*     */   }
/*     */   
/*     */   public FolderSyncState getFolderSyncState(int folderId) {
/*  48 */     return (FolderSyncState)this.folders.get(Integer.valueOf(folderId));
/*     */   }
/*     */   
/*     */   public FolderSyncState putFolderSyncState(int folderId, FolderSyncState folderSyncState) {
/*  52 */     return (FolderSyncState)this.folders.put(Integer.valueOf(folderId), folderSyncState);
/*     */   }
/*     */   
/*     */   public FolderSyncState removeFolderSyncState(int folderId) {
/*  56 */     return (FolderSyncState)this.folders.remove(Integer.valueOf(folderId));
/*     */   }
/*     */   
/*     */   public void setHasRemoteInboxChanges(boolean hasChanges) {
/*  60 */     this.hasRemoteInboxChanges = hasChanges;
/*     */   }
/*     */   
/*     */   public void resetHasChanges() {
/*  64 */     this.hasRemoteInboxChanges = false;
/*  65 */     this.lastChangeId = this.mbox.getLastChangeID();
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */   public boolean checkAndResetHasChanges(DataSource ds)
/*     */     throws ServiceException
/*     */   {
/*  73 */     if ((this.hasRemoteInboxChanges) || (this.lastChangeId <= 0)) {
/*  74 */       ZimbraLog.datasource.debug("Forcing sync due to remote INBOX changes");
/*  75 */       this.hasRemoteInboxChanges = false;
/*  76 */       return true;
/*     */     }
/*     */     
/*  79 */     if (this.mbox.getLastChangeID() == this.lastChangeId) {
/*  80 */       return false;
/*     */     }
/*     */     
/*     */ 
/*  84 */     FolderChanges fc = FolderChanges.getChanges(ds, this.lastChangeId);
/*  85 */     if (fc.hasChanges()) {
/*  86 */       ZimbraLog.datasource.debug("Forcing sync due to local folder changes: %s", new Object[] { fc });
/*  87 */       this.lastChangeId = fc.getLastChangeId();
/*  88 */       return true;
/*     */     }
/*  90 */     this.inboxChanges = MessageChanges.getChanges(ds, this.inboxFolder, this.lastChangeId);
/*  91 */     this.lastChangeId = Math.min(this.inboxChanges.getLastChangeId(), fc.getLastChangeId());
/*  92 */     if (this.inboxChanges.hasChanges()) {
/*  93 */       ZimbraLog.datasource.debug("Forcing sync due to local INBOX changes: %s", new Object[] { this.inboxChanges });
/*  94 */       return true;
/*     */     }
/*  96 */     return false;
/*     */   }
/*     */   
/*     */   public MessageChanges getInboxChanges() {
/* 100 */     return this.inboxChanges;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/imap/SyncState.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */